	<!--模态框（Modal） -->
	<div class="modal fade bs-example-modal-lg text-center" id="showBusLocModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog modal-lg" style="display: inline-block; width: auto;">
		<div class="modal-content">
			<img  id="imgInModalID" src="" > 
		</div>
		</div>
	</div>
	<!-- /.modal --> 
	<div class="modal fade" id="showBusTimeTableModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title">发车时间表</h4>
				</div>
				<div class="modal-body">
					<table id="busTimetable"></table>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->

<div >
	<div id="toolbar">
		
	</div>
	<table id="table"
			data-show-multi-sort="true" 
			data-show-export="true"
			data-sort-priority='[{"sortName": "bID","sortOrder":"asc"}]'
			>
	</table>
</div>

	<script>
			$('body').append($('#showBusLocModal'));
			$('body').append($('#showBusTimeTableModal'));

           var options = {
				ajax : function (request) {
					console.log(request);
					$.ajax({
						type: "get",
						url: "//api.waitbus.com/v3/?mothed=getBuses",
						data: request.data,
						dataType: 'json',
						success: function (data, status,request) {
								$('#table').bootstrapTable('load', data.result);
								$('#table').bootstrapTable('hideLoading');
						},
						error: function () {
							
							
						}
					});
				},
					
                columns: [{
                    field: "bID",
                    title: "bID",
					sortable:true,
                    filter: {
                        type: "input"
						
                    },
					cardVisible:false,
					visible: false
                }, {
                    field: "bName",
                    title: "自编号",
					sortable:true,
                    filter: {
                        type: "input"
						
                    }
                }, { 
                    field: "bCardID",
                    title: "车牌号",
                    filter: {
                        type: "input"
						
                    },
					sortable:true,
					editable:false
                }, {
                    field: "lID",
                    title: "线路ID",
                    filter: {
                        type: "input"
                    },
					sortable:true,
					cardVisible:false,
					visible: false
                }, {
                    field: "lName",
                    title: "线路名",
                    filter: {
                        type: "input"
                    },
					cardVisible:true,
					sortable:true,
					visible: true
                }, {
                    field: "lStartName",
                    title: "线路起点",
                    filter: {
                        type: "input"
                    },
					cardVisible:false,
					sortable:true,
					visible: false
				}, {
                    field: "bStation",
                    title: "发出站点",
                    filter: {
                        type: "input"
                    },
					sortable:true,
					editable:false
                }, {
                    field: "lEndName",
                    title: "线路终点",
                    filter: {
                        type: "input"
                    },
					cardVisible:false,
					sortable:true,
					visible: true
                }, {
                    field: "lCompany",
                    title: "车队",
                    filter: {
                        type: "input"
                    },
					cardVisible:false,
					sortable:true,
					visible: false
                }, {
                    field: "bDecorate",
                    title: "涂装",
                    filter: {
                        type: "input"
                    },
					sortable:true,
					cardVisible:true,
					visible: true
                }, {
                    field: "bClass",
                    title: "车型",
                    filter: {
                        type: "select",
                        data: ["全选","BJ6123C7C4D","DD6181S03","JK6106GBEVQ4","JK6106GPHEVN5Q2","JK6109GHEVN52","JK6109GHEVN53","JK6109GN5","JK6120D","JK6126GPHEVN5Q2","JK6129GHEVN52","JK6856GBEV","JNP6120G-3","JNP6180GVC","JNP6182G-1","JS6126GHCP","LCK6112G-3","LCK6121HEV","LCK6123GEV","LCK6125G-2","LCK6125HQGN","LCK6125PHENV","LCK6140HGN","LCK6180G-1","LCK6180HQGNA","LCK6809EVG6","LCK6950HG","LCK6950HGN","XML6125J15CN","XML6700J18C","XMQ6105G2","ZK5125A","ZK6125BEVG5","ZK6125HNG2","ZK6641BEVG4","ZK6805BEVG3","LCK6107PHEVG","ZK6105CHEVPG4"]
                    },
					cardVisible:true,
					sortable:true,
					visible: true
                }, {
                    field: "bCompany",
                    title: "厂商",
                    filter: {
                        type: "select",
                        data: ["全选","中通","亚星维特思达","厦门金旅","厦门金龙","宇通","福田","重汽·豪沃","青年","黄河","黄海"]
                    },
					sortable:true,
					cardVisible:true,
					
                }, {
                    field: "bCalled",
                    title: "别名", 
                    filter: {
                        type: "select",
                        data: ["全选","CNG宇通","CNG豪沃","E6","e8","H10","LNG宇通","LNG青年铰接","LNG风采","一代大虫","一代小青年","小空调单机青年","一代混动","康机混动","一代混动","康机混动低地板混动 LF独苗","一代空调驴","小驴","一代绿阳光","高顶绿阳光","三代油混","三代空调驴","中通小电动","二代LNG豪沃","二代大虫","二代大豪沃","二代小青年","大空调单机青年","二代插电小豪沃","双开门插电小豪沃","二代混动","亚星空混","兔耳版空调驴","十米大电动","双开门风采单机","大青年","大驴","单胎驴","大黄后","宇电","宇通混动","小阳光","矮阳光","小风采","矮风采","彩椒","大风采","彩电","中通电车","彩电样车","插电大豪沃","插电小豪沃","枣泥豪沃","一代豪沃","气混","济客电车","双源济客","福混","考驴","蓝阳光","豪沃电动","金龙","非空青年","简配青年","非空驴","风采三轴","风采混动"]
                    },
					sortable:true
                }, {
                    field: "bLength",
                    title: "长度",
                    filter: {
                        type: "select",
                        data: ["全选","6.4m","7m","8.5m","8m","9.5m","10.5m","11m","12m","13.7m","18m通道"]
                    },
					sortable:true,
					cardVisible:false,
					visible: true
                }, {
                    field: "bAir",
                    title: "空调",
                    filter: {
                        type: "select",
                        data: ["全选","无空调","有，永久不开","空调开放"]
                    },
					sortable:true,
					visible: false,
					formatter:bAirFormatter
                }, {
                    field: "bEnergy",
                    title: "动力源",
                    filter: {
                        type: "select",
                        data: ["全选","CNG","CNG+压缩空气起步","CNG气电混动","LNG","LNG气电混动","双源无轨电车","双源电车","插电式气电混合动力","插电式混合动力","柴油","油电混动","纯电动"]
                    },
					sortable:false,
					cardVisible:true,
					visible: true
                }, {
                    field: "bStair",
                    title: "台阶",
                    filter: {
                        type: "select",
                        data: ["全选","1级台阶","2级台阶","3级台阶"]
                    },
					sortable:true,
					cardVisible:false,
					visible: false,
					formatter:bStairFormatter
                }, {
                    field: "bWheel",
                    title: "轮椅停靠",
                    filter: {
                        type: "select",
                        data: ["全选","有轮椅停靠位","无轮椅停靠位"]
                    },
					sortable:true,
					cardVisible:false,
					visible: false,
					formatter:bWheelFormatter
                }, {
                    field: "bYear",
                    title: "购入年",
                    filter: {
                        type: "select",
                        data: ["全选","2018","2017","2016","2015","2014","2013","2012","2011","0"]
                    },
					sortable:true,
					cardVisible:false,
					visible: false
                }, {
                    field: "bTimestamp",
                    title: "上次更新",
                    filter: {
                        type: "select",
                        data: ["全选","在运营","1天内上线过","7天内上线过","30天内上线过","30天前上线过"]
                    },
					sortable:true,
					cardVisible:true,
					visible: true,
					formatter:timeFormatter
				}, {
                    field: "bVelocity",
                    title: "车速",
                    filter: {
                        type: "select",
                        data: ["全选","不为0"]
                    },
					sortable:true,
					formatter:bVelocityFormatter
				}, {
                    field: "map",
                    title: "位置",
					formatter:mapFormatter
				}, {
                    field: "timetable",
                    title: "发车表",
					formatter:timetableFormatter
                }],
                filter: true,
				pagination: true,
				showColumns:true,
				striped:true,
				pageSize:15,
				sidePagination:"server",
				smartDisplay:true,
				showFullscreen:true,
				pageList: [5, 10, 15, 20, 30, 50,"ALL"],
				clickToSelect: false,
				showRefresh: true,
				showToggle: true,
				toolbar: "#toolbar",
				responseHandler:function(res){
						console.log(res);
						return res;
					},
				onClickCell:pausekm,
				onEditableSave: function (field, row, oldValue, $el) {
					console.log(row);
					$.ajax({
						type: "get",
						url: "https://api.waitbus.com/v3/?mothed=getBuses",
						data: row,
						dataType: 'JSON',
						success: function (data, status) {
							if (status == "success") {
								swal("已保存", "", "success");
								$(".editable-unsaved").removeClass("editable-unsaved");
							}
						},
						error: function () {
							swal("网络异常或失败", "请检查网络连接，也可能是服务器暂时故障", "error");
							
						},
						complete: function () {

						}
						
					});
				}
            };
			if($(window).width()<400){
				options.cardView=true;
				options.pageSize=3;
			}else{
				
			}
			loadTable();
		function loadTable(){
			try{$("#table").bootstrapTable(options)}
			catch(e){
				setTimeout(function (){
					loadTable();
				},1000);
			}
			setTimeout(function(){
				$('.fixed-table-container').css("max-height","" + ($(window).height() - $('.fixed-table-container').position().top - 100) + "px")
				$('.fixed-table-container').css("overflow-y","auto")
			},1000);
		}
		
		function timeFormatter(value, row, index) {
			var res = '';
			if(value==0){
				res = '不存在记录';
			}else{
				if(Date.parse(new Date())/1000 - value<60){
					res = "1分钟内";
				}else{
					if(Date.parse(new Date())/1000 - value<3600){
						res = Math.round((Date.parse(new Date())/1000 - value)/60) + "分钟前" ;
					}else{
						if(new Date(new Date().setHours(0, 0, 0, 0)) / 1000 < value){
							res=new Date(value * 1000).format("hh:mm"); 
						}else{
							res=new Date(value * 1000).format("yy-MM-dd hh:mm"); 
						}
					} 
				} 

			}
			return res;
		}
		function mapFormatter(value, row, index) {
			return '<a herf="javascript:void(0)" data-toggle="modal" data-target="#showBusLocModal" >显示地图</a>';
		}
		function timetableFormatter(value, row, index) {
			return '<a herf="javascript:void(0)" data-toggle="modal" data-target="#showBusTimeTableModal" >发车表</a>';
		}
		function bAirFormatter(value, row, index) {
			var res = ["无空调","有，永久不开","空调开放"];
			return res[value];
		}
		function bStairFormatter(value, row, index) {
			return value+"级台阶";
		}
		function bWheelFormatter(value, row, index) {
			return (value?'有':'无');
		}
		function bVelocityFormatter(value, row, index) {
			return value.toFixed(2) + '千米/时';
		}
		function lineFormatter(value, row, index) {
			return row['lName'] + ' ' + row['lStartName'] + ' - ' + row['lEndName'];
		}
		function pausekm(field, value, row, $element) {
			console.log(row)
			if(field=='map'){
				$.ajax({
					type: "get",
					url: "//api.waitbus.com/v3/?mothed=getBusBybID&bid=" + row['bID'],
					dataType: 'json',
					success: function (data, status,request) {
						if($(window).width()>900){
							$('#imgInModalID').attr('src', "//restapi.amap.com/v3/staticmap?zoom=16&size=800*600&markers=,,:" +  (parseFloat(data.result.bLng)+0.00591823) + ',' + (parseFloat(data.result.bLat)+0.00031088)  + "&key=e8985788ebcc94a2d16bc4d813c072eb")
						}else{
							$('#imgInModalID').attr('src', "//restapi.amap.com/v3/staticmap?zoom=14&size="+ Math.round($(window).width()*0.9) +"*" + Math.round($(window).height()*0.9)  +"&markers=,,:" +  (parseFloat(data.result.bLng)+0.00591823) + ',' + (parseFloat(data.result.bLat)+0.00031088)  + "&key=e8985788ebcc94a2d16bc4d813c072eb")
						
						}
					},
					error: function () {
						alert('载入地图数据失败');
					}
				});

			}
			if(field == "timetable"){
				var busTimeTableoptions = {
					ajax : function (request) {
						console.log(request);
						$.ajax({
							type: "get",
							url: "//api.waitbus.com/v3/?mothed=getBusTimeTable&bid=" + row['bID'],
							dataType: 'json',
							success: function (data, status,request) {
									$('#busTimetable').bootstrapTable('load', data.result);
									$('#busTimetable').bootstrapTable('hideLoading');
							},
							error: function () {
								alert('加载失败');
							}
						});
					},
					columns: [{
						field: "tLine",
						title: "线路",
						formatter:lineFormatter
					}, { 
						field: "tStartTime",
						title: "发车时间",
						formatter:timeFormatter
					}, {
						field: "tEndTime",
						title: "预计到达",
						formatter:timeFormatter
					}]
				}
				$("#busTimetable").bootstrapTable('destroy');
				$("#busTimetable").bootstrapTable(busTimeTableoptions);
				
			}
		}
    </script>
</body>
</html>
